import 'dart:async';
import 'dart:io';

import 'package:aliplayer_widget/utils/log_util.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_sign_in/google_sign_in.dart';
// import 'package:google_sign_in/google_sign_in.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';

import 'index.dart';

class LoginPage extends GetView<LoginController> {
  const LoginPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // 自定义返回按钮
        leading: IconButton(
          icon: const Icon(Icons.arrow_back, color: Colors.white), // 强制白色
          onPressed: () => Navigator.of(context).pop(), // 返回上一页
        ),
        // backgroundColor: Colors.blue, // 确保与白色文字有对比
      ),
      body: SafeArea(
        // 背景图片设置，使用 DecoratedBox + DecorationImage
        child: DecoratedBox(
          decoration: const BoxDecoration(
            image: DecorationImage(
              // 背景图片，替换为实际图片名称，假设背景图是 bg.png
              image: AssetImage('assets/images/loginbg.png'),
              fit: BoxFit.cover,
            ),
          ),
          child: Stack(
            children: [
              // 中间 Logo，根据实际调整位置和大小
              Positioned(
                top: MediaQuery.of(context).size.height * 0.3,
                left: MediaQuery.of(context).size.width * 0.25,
                child: Image.asset(
                  'assets/images/logo1.png', // 替换为实际 Logo 图片名称
                  width: 200,
                  height: 80,
                ),
              ),
            
              // 底部登录按钮区域，通过 Positioned 调整位置，也可用 Align 等方式
              Positioned(
                bottom: 100 / 2,
                left: 71 / 2,
                right: 71 / 2,
                child: Column(
                  children: [
                    // Apple 登录按钮
                    Platform.isIOS
                        ? ElevatedButton(
                            onPressed: () {
                              controller.signInWithApple();
                            },
                            style: ElevatedButton.styleFrom(
                              backgroundColor: const Color(0xFF2C3033), //
                              foregroundColor: Colors.white,
                              minimumSize: const Size(608 / 2, 89 / 2),
                            ),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Image.asset(
                                  'assets/images/apple.png', // 替换为实际 Apple 图标名称
                                  width: 24,
                                  height: 24,
                                ),
                                const SizedBox(width: 8),
                                Text('通过 Apple 登录'.tr),
                              ],
                            ),
                          )
                        : SizedBox(),
                    const SizedBox(height: 16),
                    // Google 登录按钮
                    ElevatedButton(
                      onPressed: () {
                        controller.signInWithGoogle();
                      },
                      style: ElevatedButton.styleFrom(
                        backgroundColor: Colors.white,
                        foregroundColor: Colors.black87,
                        minimumSize: const Size(608 / 2, 89 / 2),
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Image.asset(
                            'assets/images/google.png', // 替换为实际 Google 图标名称
                            width: 24,
                            height: 24,
                          ),
                          const SizedBox(width: 8),
                          Text('通过 Google 登录'.tr),
                        ],
                      ),
                    ),

                    const SizedBox(height: 16),
                    // Facebook 登录按钮
                    ElevatedButton(
                      onPressed: () {
                        controller.signInWithFacebook();
                      },
                      style: ElevatedButton.styleFrom(
                        backgroundColor: Colors.blue,
                        foregroundColor: Colors.white,
                        minimumSize: const Size(608 / 2, 89 / 2),
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Image.asset(
                            'assets/images/tempfacebook.png', // 替换为实际 Facebook 图标名称
                            width: 24,
                            height: 24,
                          ),
                          const SizedBox(width: 8),
                          Text('通过 Facebook 登录'.tr),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
